#include<iostream>
#include<stack>
#include<string>
using namespace std;
string op,s;
stack<string> s1,s2;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> op;
		if(op=="VISIT"){
			cin >> s;
			while(!s2.empty()){
				s2.pop();
			}
			s1.push(s);
		}else if(op=="BACK"){
			if(s1.size()<=1){
				cout << "Ignore" << endl;
				continue;
			}
			s2.push(s1.top());
			s1.pop();
		}else{
			if(s2.empty()){
				cout << "Ignore" << endl;
				continue;
			}
			s1.push(s2.top());
			s2.pop();
		}
	}
	return 0;
}
